<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;

use app\common\builder\TableBuilder;
use app\common\builder\TableFront;

class OrderVideo extends Base
{

    //主键，默认为id
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\OrderVideo';


    //关联模型
    protected $hasOne = ['user', 'level'];

    protected $sort = 'id,desc';

    //抽奖记录
    public function index()
    {
        return $this->setTable('index');
    }

    public function setTable($action, $extra_map = ['pay_state'=>1])
    {
        //构建table
        $tableFront = TableFront::getInstance()
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addRow(['field' => 'nickname', 'title' => '昵称', 'templet' => '<div>{{d.user.nickname}}</div>'])
            ->addRow(['field' => 'code', 'title' => '编号', 'templet' => '<div>{{d.user.code}}</div>'])
            ->addRow(['field' => 'mobile', 'title' => '手机号', 'templet' => '<div>{{d.user.mobile}}</div>'])
            ->addRow(['field' => 'pay_time', 'title' => '支付时间'])
            ->addRow(['field' => 'pay_way', 'title' => '支付方式'])
            ->addRow(['field' => 'real_amount', 'title' => '支付金额'])
            ->addRow(['field' => 'level_video_id', 'title' => '等级', 'templet' => '<div>{{d.level.title}}</div>'])
            ->addRow(['field' => 'red_coin', 'title' => '已获得积分的金额'])
            ->addRow(['field' => 'max_red_coin', 'title' => '最高可获得积分的金额']);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->setSearch($this->setSearch($action))
            ->addExtraMap($extra_map)
            ->fetch();
    }


    public function setSearch($action)
    {
        return TableFront::getInstance()
            ->setSearch(['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id']);
    }


}
